﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Leiktuther.Models;
//using Leiktuther.ViewModels;

namespace Leiktuther.Controllers
{
    public class HomeController : Controller
    {
        private IAppRepository _repository = null;

        public HomeController()
        {
            _repository = new AppRepository();
        }

        public HomeController(IAppRepository rep)
        {
            _repository = rep;
        }
        // Front Site
        public ActionResult Index()
        {        
            var model = _repository.Games;
            return View(model);
        }
        // Show Statistics
        public ActionResult Statistics()
        {
            GameRepository _gameRepo = new GameRepository();
            var model = _gameRepo.getPlayerStatistics();
            return View(model);
        }

        public ActionResult Admin()
        {
            return View();
        }

        public ActionResult List()
        {
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        [HttpPost]
        public ActionResult About( GameInstance model)
        {
            try
            {
                GameRepository _gameRepo = new GameRepository();
                _gameRepo.AddInstance(model);
                return RedirectToAction("About", "Home");
            }
            catch
            {
                return RedirectToAction("Home");
            }
        }

        public ActionResult AboutIt()
        {
            return View();
        }

        [HttpPost]
        public ActionResult AboutIt( Statistic model )
        {
            try
            {
                GameRepository _gameRepo = new GameRepository();
                _gameRepo.AddStatistic(model);
                return RedirectToAction("AboutIt", "Home");
            }
            catch
            {
                return RedirectToAction("Home");
            }
        }

        public ActionResult AboutThat()
        {
            return View();
        }
        
        [HttpPost]
        public ActionResult AboutThat(Game model)
        {
            GameRepository _gameRepo = new GameRepository();
            _gameRepo.AddGames(model);
            return RedirectToAction("AboutThat", "Home");
        }
    }
}
